<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html style="height: 100%;">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>左侧菜单树</title>
<%@ include file="/WEB-INF/jsp/kt/common/inc.jsp" %>
<script type="text/javascript" src="${_resources}js/jquery.ztree.core.js"></script>
<link type="text/css" rel="stylesheet" href="${_resources}css/zTreeStyle.css">

<style type="text/css">
body{	
	overflow:hidden;
}
</style>
<script type="text/javascript">
	var ztree;
	var menuId = "";
	var menuName="";
	var setting = {	
		view: {
			showLine: true,
			selectedMulti: false,
			addDiyDom: addDiyDom,
			dblClickExpand: false	
		},
		data: {
			simpleData: {
				enable: true,
				idKey: "menuId",
				pIdKey: "parentId"
			}
		},
		callback: {
			onNodeCreated: this.onNodeCreated,				
			onClick:onClick			
		}
	};
	
	var zNodes = eval('(${menuList})');
	
	var parentMenuId = "${menuInfo.menuId}";
	$(document).ready(function(){
		ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
		var nodes = ztree.getNodes();
		for(var i = 0 ; i < nodes.length ; i++){
			if(nodes[i].name == "KT资产信息审核" || nodes[i].name == "资产信息审核" || 
			  nodes[i].name == "需求管理基础数据" || nodes[i].name == "需求类型" || 
			  nodes[i].name == "需求级次" || nodes[i].name == "变更类型" || 
			  nodes[i].name == "调查方式" || nodes[i].name == "需求状态" || 
			  nodes[i].name == "基线类型"){
				ztree.removeNode(nodes[i]);
			}
		}
		
		//ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
		ztree.selectNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//选中指定节点
		ztree.setting.callback.onClick(null, ztree.setting.treeId, ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//触发函数
	});
	
	function addDiyDom(treeId, treeNode) {
		var liObj = $("#" + treeNode.tId);
		var aObj = $("#" + treeNode.tId + "_span");
		liObj.addClass("level_"+treeNode.level);
		aObj.addClass("le_"+treeNode.level);
	};

	function onClick(e,treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.expandNode(treeNode);
		menuName = treeNode.name;
		menuId = treeNode.menuId;
		var div = document.getElementById("rightIframe");
		if(treeNode.level == '0' && menuName != "典型测试需求库" && menuName != "典型测试项库"){
			$("#submitData").hide();
		}else{
			$("#submitData").show();
		}
		if(menuName === "文档通用章节"){
			treeNode.menuUrl ="/organizeassets/showOrganizeassets";
		}

		div.src ="${_baseUrl}"+treeNode.menuUrl+"?menuId="+treeNode.menuId+"&source=${source}&setPageSize=${setPageSize}&quote=quote&status=1&isCopy=1"+"&rand="+Math.random() ;


	}
	
	//提交数据
	function submitData(){
		if(parentMenuId == "11111"){
			submitData2();
			return;
		}
		
		layer.load(1);
		if(menuName=="软件管理类"||menuName=="软件测试类"||menuName=="软件设计类"){
			layer.msg("请先选择可引用的数据分类",{time:1500});
			return;
		}
		var objects = document.getElementById('rightIframe').contentWindow.getSelect();
		var getTableTitle = document.getElementById('rightIframe').contentWindow.getTableTitle();
		if(objects.length == 0){
			layer.msg("请先选择要引用的数据",{time:1500});
			return;
		}
		layer.load(1);
		/* setTimeout(function(){
		  layer.closeAll('loading');
		}, 3000); */
		
		setTimeout(function () {
			parent.getTableData(objects,getTableTitle);
			cancelAndClose();
		 },2000);
		
	}
	
	function submitData2(){
		$("#submit").attr("onclick","");
		if(menuName=="软件管理类"||menuName=="软件测试类"||menuName=="软件设计类"){
			layer.msg("请先选择可引用的数据分类",{time:1500});
			$("#submit").attr("onclick","submitData()");
			return;
		}
		var selectId = document.getElementById('rightIframe').contentWindow.getSelect();
		if(selectId==""){
			layer.msg("请先选择要引用的数据",{time:1500});
			$("#submit").attr("onclick","submitData()");
			return;
		}
		
		var insertWay = "";
		if(menuName=="测试类文档资产信息"||menuName=="设计类文档资产信息"||menuName=="管理类文档资产信息"){
			var rightIframe = document.getElementById('rightIframe').contentWindow;
			var radio = rightIframe.document.getElementsByName("insertWay");
            for(var i=0; i<radio.length; i++){
                if(radio[i].checked==true) {
                	insertWay = radio[i].value;
                    break;
               }
           }
            
           if(insertWay == ""){
        	   layer.msg("请至少选择一种添加方式",{time:1500});
        	   $("#submit").attr("onclick","submitData()");
   			   return;
           }
		}
		
		layer.msg('添加中,请稍后...', {icon: 16},function(){
			parent.closeLayer();
		});
		if(insertWay == "1"){
			parent.getOrgSectionData(selectId);
		}else{
			$.ajax({    
				type: "POST",    
				async: false,    
				url:"${_baseUrl}/referOrganize/getTableData",
				data:{
					"selectId":selectId,
					"menuName":menuName,
					"menuId" : menuId,
					"sectionId":"${sectionId}",
					"token":"${token}"
				},
				dataType:"json",    
				success: function (data) {  
					var tableContent = data;
					parent.getTableData(tableContent,menuName,selectId,menuId);
				},
				error:function(){
					layer.msg("系统错误，请重新选择引用",{time:2000},function(){
						parent.closeLayer2();
					});
				}
			}); 
		}
	}
	
   function cancelAndClose(){
	   parent.closeLayer();
   }
</script>
<style>
	.ztree li span.button{width:0px}
	.ztree li a.curSelectedNode{background-color: #fff;border:0px}
	.ztree li a:hover{text-decoration : none }
	.main_center .doc_tree .ztree li.level0 a .node_name{max-width: 205px;}
	.main_center .doc_tree .ztree li.level1 a .node_name{max-width: 185px;}
	.main_center .doc_tree .ztree li.level2 a .node_name{max-width: 160px;}
	.main_center .doc_tree .ztree li.level3 a .node_name{max-width: 140px;}
	.main_center .doc_tree .ztree li.level4 a .node_name{max-width: 120px;}
	.main_center .doc_tree .ztree li.level5 a .node_name{max-width: 100px;}
	.zuzhizyy_btn{position: fixed;bottom: -10px;left:20%;margin-bottom: 10px;z-index: 9999999999;width:80%;}
	.submit_group{margin-top:0px}
	.menu_tit{margin: 10px 0 0 15px;font-size: 13px;color: rgb(102, 102, 102);}
	.doc_tree{margin-left:15px}
</style> 
</head>
<body style="height: 100%;">
	<div class="ma main">
		<!-------左侧菜单------>
		<div id="main-center" class="zTreeDemoBackground main_center">
			<div class="menu_tit">${menuInfo.menuName}</div>
	        <div class="doc_tree">
	            <ul id="treeDemo" class="ztree"></ul>
	        </div>
	    </div>

        <!-------中间内容------>
        <div id="main-right" class="iframe_yhgl1 main_right" style="padding-bottom:50px;">
        	<iframe id="rightIframe" frameborder="0" style="width:100%; height:100%;" src=""></iframe>     
        </div>    
	    <div class="zuzhizyy_btn">
			<div class="submit_group">
				<a href="javascript:;" class="submit" id ="submitData"  onclick="submitData()">提交</a>
				<a href="javascript:;" class="cancel" onclick="cancelAndClose()">取消</a>
			</div>
		</div>  
         
    	<div class="clear"></div>
    </div>
</body>
<script type="text/javascript">
    var  resizeTimer = null;
    window.onload = function(){
        initWidth();
        initHeight();
    }
    window.onresize = function(){
        if(resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout("initHeight();initWidth();",100);
    }
    function initHeight(){
        var topH = 0;
        if(navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("like Gecko")>0) {//IE浏览器
            initheight = document.documentElement.clientHeight-topH;
        }
        if(navigator.userAgent.indexOf("Firefox")>0){//Firefox浏览器
            initheight = document.documentElement.clientHeight-topH;
        }
        if(navigator.userAgent.indexOf("Opera")>0){//Opera浏览器
            initheight = document.body.clientHeight-topH;
        }
        if(navigator.userAgent.indexOf("Chrome")>0){//Chrome谷歌浏览器
            initheight = document.documentElement.clientHeight-topH;
        }
        if(navigator.userAgent.indexOf("Safari")>0){//Safari浏览器
            initheight = document.documentElement.clientHeight-topH;
        }
    }
    function initWidth(){
        var oMaBox = document.getElementById("main-center");
        var topW = oMaBox.getBoundingClientRect().width;

        if(navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("like Gecko")>0) {//IE浏览器
            topW = oMaBox.clientWidth;
            initwidth = document.documentElement.clientWidth-topW;
        }
        if(navigator.userAgent.indexOf("Firefox")>0){//Firefox浏览器
            initwidth = document.documentElement.clientWidth-topW;
        }
        if(navigator.userAgent.indexOf("Opera")>0){//Opera浏览器
            initwidth = document.body.clientWidth-topW;
        }
        if(navigator.userAgent.indexOf("Chrome")>0){//Chrome谷歌浏览器
            initwidth = document.documentElement.clientWidth-topW;
        }
        if(navigator.userAgent.indexOf("Safari")>0){//Safari浏览器
            initwidth = document.documentElement.clientWidth-topW;
        }
        $("#main-right").css( {"width":initwidth-5,"position":"absolute","left":topW});
    }
</script>
</html>